Skip to content

Migrate avoid unrelated type assertions and its tests#239

Open
daria-trusca-solid wants to merge 5 commits into
analysis_server_migrationfrom
migrate_avoid_unrelated_type_assertions
Open

Migrate avoid unrelated type assertions and its tests#239
daria-trusca-solid wants to merge 5 commits into
analysis_server_migrationfrom
migrate_avoid_unrelated_type_assertions

Conversation

@daria-trusca-solid
Copy link
Copy Markdown
Collaborator

Migrated the avoid_unrelated_type_assertions rule and its corresponding tests to comply with the analyzer package.

Changes

  • Rule Refactoring: Updated the implementation of avoid_unrelated_type_assertions to use the current analyzer syntax.
  • Tests: Updated and verified all associated test cases to ensure the rule triggers correctly and no regressions are introduced.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request migrates the avoid_unrelated_type_assertions lint rule from custom_lint_builder to the standard analyzer package's AnalysisRule framework, updating the rule registration, refactoring the visitor to report diagnostics directly, and adding comprehensive unit tests. The feedback suggests changing the visitor's base class from RecursiveAstVisitor to SimpleAstVisitor to avoid redundant AST traversals since the visitor is already registered specifically for IsExpression nodes.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

/// AST Visitor which finds all is expressions and checks if they are
/// unrelated (result always false)
/// Visitor for [AvoidUnrelatedTypeAssertionsRule].
class AvoidUnrelatedTypeAssertionsVisitor extends RecursiveAstVisitor<void> {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since this visitor is registered specifically for IsExpression nodes via registry.addIsExpression, the analyzer engine will automatically traverse the AST and dispatch all IsExpression nodes to this visitor.\n\nUsing RecursiveAstVisitor causes the visitor to recursively traverse the AST children of each IsExpression node again. This leads to redundant traversals and can cause nested IsExpression nodes to be visited and reported multiple times.\n\nChanging the base class to SimpleAstVisitor avoids this redundant traversal and ensures each node is processed exactly once.

Suggested change
class AvoidUnrelatedTypeAssertionsVisitor extends RecursiveAstVisitor<void> {
class AvoidUnrelatedTypeAssertionsVisitor extends SimpleAstVisitor<void> {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant